package com.sloera.springcloud.payment.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sloera.java.common.tool.entity.CommonResultCode;
import com.sloera.java.common.tool.entity.R;
import com.sloera.springcloud.payment.entity.Payment;
import com.sloera.springcloud.payment.service.PaymentService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author sloera
 * @since 2020-08-04
 */
@RestController
@Slf4j
@Api(value = "支付模块")
public class PaymentController {
    @Resource
    private PaymentService paymentService;

    @PostMapping(value = "/payment/create")
    public R<Integer> create(Payment payment) {
        int result = paymentService.create(payment);
        log.info("插入结果：" + result);
        if (result > 0) {
            return R.data(200, result, "插入数据库成功");
        } else {
            return R.fail(CommonResultCode.FAILURE, "插入数据库失败");
        }
    }

    @GetMapping(value = "/payment/get/{id}")
    public R<Payment> getPaymentById(@PathVariable("id") Long id) {
        Payment payment = paymentService.getPaymentById(id);
        Page<Payment> page = new Page<>(1, 10);
        System.out.println(paymentService.selectPaymentPage(page, id.toString()));
        log.info("查询结果：" + payment);
        if (payment != null) {
            return R.success(payment);
        } else {
            return R.fail("查询失败，查询ID：" + id);
        }
    }
}
